package com.dg11185.nearshop.activity.home;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewStub;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.SimpleAdapter;
import android.widget.TabHost;
import android.widget.TextView;

import com.android.nearshop.R;
import com.dg11185.libs.network.NetClient;
import com.dg11185.libs.network.http.client.HttpRequest.ActionListener;
import com.dg11185.nearshop.activity.BaseFragment;
import com.dg11185.nearshop.activity.shop.ShopDetailActivity;
import com.dg11185.nearshop.activity.welcome.MainTabActivity;
import com.dg11185.nearshop.app.Constants;
import com.dg11185.nearshop.app.StaticData;
import com.dg11185.nearshop.baidumap.NearshopActivity;
import com.dg11185.nearshop.baidumap.mai.ShakeListener;
import com.dg11185.nearshop.baidumap.mai.ShakeListener.OnShakeListener;
import com.dg11185.nearshop.net.entity.Area;
import com.dg11185.nearshop.net.request.GetAreaListRequest;
import com.dg11185.nearshop.net.request.GetBrandListRequest;
import com.dg11185.nearshop.net.request.GetDayMerListRequest;
import com.dg11185.nearshop.net.response.GetAreaListResponse;
import com.dg11185.nearshop.net.response.GetBrandListResponse;
import com.dg11185.nearshop.net.response.GetDayMerListResponse;
import com.dg11185.nearshop.view.ExpandTabView;
import com.dg11185.nearshop.view.TwoLevelCatalogView;
import com.dg11185.nearshop.view.TwoLevelCatalogView.OnSelectListener;
import com.dg11185.nearshop.view.adapter.F_ShopListAdapter;
import com.dg11185.nearshop.view.adapter.V_ShopListAdapter;
import com.wlper.lib.uitls.LogUtils;
import com.wlper.lib.uitls.ViewUtils;
import com.wlper.lib.view.loading.BaseLoadLayout.LoadStateHandler;
import com.wlper.lib.view.loading.LoadLayoutWithFrameAnim;

/**
 * 首页
 * 
 * @author wanliang527
 * @date 2014-5-9
 * @deprecated 已被{@link}HomeFragment2取代
 */
public class HomeFragment extends BaseFragment implements
        OnCheckedChangeListener {

    private final static String GD_ID = "20";
    private final static String DG_AREA_NUM = "0001900017";
    private final static String DG_ID = "249";
    private final static int PAGE_SIZE = 5;
    private final static long RELOAD_F_DELLAY = 500;
    private final static long RELOAD_AREA_DELLAY = 1500;

//    private String mCurArea;// 当前区域
//    private String mCurType;// 当前商家类别

    private GridView shopType, newestActivities;
    private RadioGroup mRadioGroup;
    private TabHost mTabHost;
    private ViewStub newestActivitiesView;
    private Handler handler = new Handler();
//    private GetBrandListResponse mBrandListRet;
//    private GetDayMerListResponse mDayMerListRet;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    @Override
    public View setContentView() {
        View view = mInflater.inflate(R.layout.fragment_home, null);
        initView(view);
        return view;
    }

    // 震动监听器的生命周期是onResume->onPause
    @Override
    public void onResume() {
        super.onResume();
        initShakeListener();
        shakeListener.start();
    }

    @Override
    public void onPause() {
        super.onPause();
        shakeListener.stop();
    }

    private int reGetAreaTimes = 0;
    private final static int MAX_RELOAD_TIMES = 5;

    private boolean alGotAreaList;

    /**
     * 联网获取地区列表
     */
    private void onGetAreaList() {
        GetAreaListRequest req = new GetAreaListRequest(DG_ID);
        req.setActionListener(new ActionListener<GetAreaListResponse>() {

            @Override
            public void onSuccess(GetAreaListResponse result) {
                Log.i("test", Constants.getAreaList + "\n" + result.responseStr);
                if (result.statusStr.equals("SUCCESS")) {
                    if (alGotAreaList) {
                        return;
                    }
                    updateAreaFilter(result);
                    alGotAreaList = true;
                } else {
                    if (reGetAreaTimes < MAX_RELOAD_TIMES)
                        onGetAreaList();
                }
            }

            @Override
            public void onFailure(int resultCode) {
                if (reGetAreaTimes < MAX_RELOAD_TIMES)
                    onGetAreaList();
            }
        });
        NetClient.httpPost(req);

    }

    /**
     * 更新地区筛选栏视图
     */
    private void updateAreaFilter(GetAreaListResponse response) {

        // 标题栏上地区筛选下拉框
        final ExpandTabView mExpandTabView = new ExpandTabView(mActivity);
        ArrayList<View> viewList = new ArrayList<View>();
        List<Area> areaList = response.areas;
        ArrayList<String> areaStrList = new ArrayList<String>();
        areaStrList.add("全城");
        for (int i = 0; i < areaList.size(); i++) {
            Area area = areaList.get(i);
            areaStrList.add(area.name);
        }

        final TwoLevelCatalogView reginSpinnerView = new TwoLevelCatalogView(
                mActivity, areaStrList, StaticData.getRegionSecLevCatelog());
        reginSpinnerView.setSecListBg(R.color.transparent);
        // reginSpinnerView.setNormalBg2(getResources().getDrawable(R.color.transparent));
        // reginSpinnerView.setSelectedBg2(getResources().getDrawable(R.color.transparent));
        reginSpinnerView.setOnSelectListener(new OnSelectListener() {

            @Override
            public void getValue(View view, int firLevPos, int secLevPos,
                    String showText) {
                String text = showText;
                if (showText.equals("不限")) {
                    text = "全城";
                }
                onRefresh(reginSpinnerView, text);

            }

            private void onRefresh(View view, String showText) {
                mExpandTabView.onPressBack();
                mExpandTabView.setTitle(showText, 0);
                // ************选择地区后的UI更新操作在此进行*******************//
//                StaticData.SHARED_DATA.put(StaticData.AREA_NUM, showText);
                ViewUtils.showToast(mActivity, showText);
            }
        });

        viewList.add(reginSpinnerView);
        String[] tabNames = new String[] { "全城" };

        mExpandTabView.initView(viewList, tabNames);
        getPartView(LEFT).addView(
                mExpandTabView,
                new LayoutParams(LayoutParams.WRAP_CONTENT,
                        LayoutParams.MATCH_PARENT));
        ((LinearLayout.LayoutParams) mExpandTabView.getLayoutParams()).leftMargin = 20;
    }

    @Override
    public boolean initTopBanner() {
        defaultInit();
        onGetAreaList();
        // 偶尔会出现无法执行onGetAreaList()的情况，用如下办法解决
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                onGetAreaList();
            }
        }, RELOAD_AREA_DELLAY);
        // 摇摇按钮
        ImageButton shakeBtn = new ImageButton(mActivity);
        shakeBtn.setTag("shake");
        shakeBtn.setOnClickListener(clickListener);
        // shakeBtn.setBackgroundColor(mActivity.getResources().getColor(
        // R.color.transparent));
        shakeBtn.setBackgroundResource(R.drawable.drawable_tp2tl_gray);
        shakeBtn.setImageResource(R.drawable.ic_shake_p1);
        getPartView(RIGHT).addView(shakeBtn);
        ((LinearLayout.LayoutParams) shakeBtn.getLayoutParams()).gravity = Gravity.CENTER;
        // 搜索按钮
        ImageButton searchBtn = new ImageButton(mActivity);
        searchBtn.setTag("search");
        searchBtn.setOnClickListener(clickListener);
        // shakeBtn.setBackgroundColor(mActivity.getResources().getColor(
        // R.color.transparent));
        searchBtn.setBackgroundResource(R.drawable.drawable_tp2tl_gray);
        searchBtn.setImageResource(R.drawable.selector_search_btn2);
        getPartView(RIGHT).addView(searchBtn);
        ((LinearLayout.LayoutParams) searchBtn.getLayoutParams()).gravity = Gravity.CENTER;

        return true;
    }

    private void findViewsId(View view) {
        shopType = (GridView) view.findViewById(R.id.grid_v_shop_type);
        mRadioGroup = (RadioGroup) view.findViewById(R.id.ra_group_tabs);
        mTabHost = (TabHost) view.findViewById(R.id.tab_host);
        newestActivitiesView = (ViewStub) view
                .findViewById(R.id.view_newest_activities);
        newestActivities = (GridView) view
                .findViewById(R.id.grid_v_newest_activities);
    }

    private ShakeListener shakeListener = null;

    private void initShakeListener() {
        shakeListener = new ShakeListener(mActivity);
        shakeListener.setOnShakeListener(new OnShakeListener() {
            @Override
            public void onShake() {
                startActivity(new Intent(mActivity, NearshopActivity.class));
            }
        });
    }

    private void initView(View view) {
        findViewsId(view);
        // 初始化商家类型选择
        shopType.setAdapter(new SimpleAdapter(mActivity, StaticData
                .getHomeShopTypes(), R.layout.shop_type_grid_v_item,
                new String[] { "name", "icon" }, new int[] {
                        R.id.txt_v_shop_type, R.id.image_v_shop_type_icon }));
        shopType.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                // **********商家类型的点击事件监听***********//
                TextView txtView = (TextView) view
                        .findViewById(R.id.txt_v_shop_type);
//                String areaNum = (String) StaticData.SHARED_DATA
//                        .get(StaticData.AREA_NUM);
//                StaticData.SHARED_DATA.put(StaticData.AREA_NUM, areaNum);
//                StaticData.SHARED_DATA.put(StaticData.INDUSTRY_NAME, txtView
//                        .getText().toString().trim());

                MainTabActivity.mTabHost.setCurrentTab(1);
                // ViewUtils.showToast(mActivity, txtView.getText().toString()
                // .trim());
            }
        });
        // 初始化精选商家和会员日商家
        mTabHost.setup();
        View v = mInflater.inflate(R.layout.view_shops_on_vip_day, null);
        view.setId(0);
        mTabHost.addTab(mTabHost.newTabSpec("精选商家").setIndicator("精选商家")
                .setContent(tabContent));
        mTabHost.addTab(mTabHost.newTabSpec("会员日商家").setIndicator("会员日商家")
                .setContent(tabContent));
        mRadioGroup.check(R.id.ra_btn1);
        mRadioGroup.setOnCheckedChangeListener(this);

        // 显示最新活动
        // ******************根据接口决定是否显示最新活动*****************//
        showNewestActyView(view);

    }

    private View.OnClickListener clickListener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            String tag = v.getTag() == null ? "" : (String) v.getTag();
            if (tag.equals("shake")) {
                startActivity(new Intent(mActivity, NearshopActivity.class));
                return;
            } else if (tag.equals("search")) {
                // **********跳到搜索界面****************//
                Intent intent = new Intent(mActivity, SearchActivity.class);
                startActivityForResult(intent, 1);
                return;
            }

            switch (v.getId()) {
                case R.id.btn_more_fea_shops:
                    // ***********跳转到精选商家二级界面***************//
                    onGetBrandList(false);

                    break;

                case R.id.btn_more_vip_shops:
                    // ***********跳转到会员日商家二级界面***************//
                    onGetDayMerList();
                    break;
            }
        }
    };

    private int fCounts = 0;// 精选商家总数
    private int fCurPage = 0;// 精选商家当前请求页码
    private int fIndex = 0;// 精选商家当前索引值

    private View fShopView, vShopView;
    private ListView fShopListView, vShopListView;
    private LoadLayoutWithFrameAnim fLoadingView, vLoadingView;
    private Button fMoreBtn, vMoreBtn;
    private F_ShopListAdapter fShopAdapter;
    private V_ShopListAdapter vShopAdapter;

    private int vCounts = 0;// 会员日商家总数
    private int vCurPage = 0;// 会员日商家当前请求页码
    private int vIndex = 0;// 会员日商家当前索引值

    // 点击去更多会员日商家界面
    private View.OnClickListener clickToMoreVipShops = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(mActivity, AllDayShopsActivity.class);
            startActivity(intent);
        }
    };

    private TabHost.TabContentFactory tabContent = new TabHost.TabContentFactory() {

        @Override
        public View createTabContent(String tag) {
            if (tag.equals("精选商家")) {
                // 精选商家页面的内容初始化
                fShopView = mInflater.inflate(R.layout.view_featured_shops,
                        null);
                fShopListView = (ListView) fShopView
                        .findViewById(R.id.list_v_shops);
                fLoadingView = (LoadLayoutWithFrameAnim) fShopView
                        .findViewById(R.id.flayout_featured_shops);
                fLoadingView.setStateHandler(new LoadStateHandler() {

                    @Override
                    public void onReload() {
                        onGetBrandList(true);
                    }

                    @Override
                    public void onLoading() {
                    }

                    @Override
                    public void onLoadSuccess() {
                    }

                    @Override
                    public void onLoadFailed() {
                    }
                });
                fMoreBtn = (Button) fShopView
                        .findViewById(R.id.btn_more_fea_shops);
                fMoreBtn.setOnClickListener(clickListener);
                fShopListView.setOnItemClickListener(new OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> parent, View view,
                            int position, long id) {
                        // *********首页精选商家的点击事件************//
                        F_ShopListAdapter.ViewHolder viewHolder = (F_ShopListAdapter.ViewHolder) view
                                .getTag();
//                        String areaNum = (String) StaticData.SHARED_DATA
//                                .get(StaticData.AREA_NUM);
//                        StaticData.SHARED_DATA.clear();
//                        StaticData.SHARED_DATA
//                                .put(StaticData.AREA_NUM, areaNum);

                        MainTabActivity.mTabHost.setCurrentTab(1);

                    }
                });

                fLoadingView.onLoading();
                onGetBrandList(true);

                // 偶尔出现无法执行onGetBrandList()，用如下办法解决
                handler.postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        if (fLoadingView.isLoading()) {
                            fCurPage = 0;
                            onGetBrandList(true);
                        }
                    }
                }, RELOAD_F_DELLAY);
                return fShopView;
            } else if (tag.equals("会员日商家")) {
                // 会员日商家页面的内容初始化
                vShopView = mInflater.inflate(R.layout.view_shops_on_vip_day,
                        null);
                ViewStub viewStub = (ViewStub) vShopView
                        .findViewById(R.id.stub_list1);
                viewStub.inflate();
                vShopListView = (ListView) vShopView
                        .findViewById(R.id.list_v_shops);
                vLoadingView = (LoadLayoutWithFrameAnim) vShopView
                        .findViewById(R.id.flayout_shops_on_vd);
                vLoadingView.setStateHandler(new LoadStateHandler() {

                    @Override
                    public void onReload() {
                        onGetDayMerList();
                    }

                    @Override
                    public void onLoading() {
                    }

                    @Override
                    public void onLoadSuccess() {
                    }

                    @Override
                    public void onLoadFailed() {
                    }
                });
                vMoreBtn = (Button) vShopView
                        .findViewById(R.id.btn_more_vip_shops);
                vMoreBtn.setOnClickListener(clickListener);
                vShopListView.setOnItemClickListener(new OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> parent, View view,
                            int position, long id) {
                        // **********首页会员日商家的点击事件************//
                        V_ShopListAdapter.ViewHolder viewHolder = (V_ShopListAdapter.ViewHolder) view
                                .getTag();
                        Intent intent = new Intent(mActivity,
                                ShopDetailActivity.class);
                        intent.putExtra("merchant_id", viewHolder.merchantId);
                        startActivity(intent);
                    }
                });

                vLoadingView.onLoading();
                onGetDayMerList();
                return vShopView;
            } else {
                return null;
            }

        }

    };

    /**
     * 联网获取会员日商家数据
     */
    private void onGetDayMerList() {
        // 判断当前加载的索引值，如果大于总数，就不进行加载
        // 首次加载时，索引值和会员日商家总数都为0，因此需要排除首次加载的情况
        if (vIndex != 0 && vIndex >= vCounts)
            return;
        int week = Calendar.getInstance(TimeZone.getTimeZone("GMT+8:00")).get(
                Calendar.DAY_OF_WEEK) - 1;
        GetDayMerListRequest req = new GetDayMerListRequest();
        req.add(GetDayMerListRequest.AREA_NUM, DG_AREA_NUM);
        req.add(GetDayMerListRequest.PAGE_NUM, ++vCurPage + "");
        req.add(GetDayMerListRequest.PAGE_SIZE, PAGE_SIZE + "");
        req.add(GetDayMerListRequest.WEEK, week + "");
        req.encryption();
        req.setActionListener(new ActionListener<GetDayMerListResponse>() {

            @Override
            public void onSuccess(GetDayMerListResponse result) {
                LogUtils.logNetReturn(Constants.getDayMerList, result.responseStr);
                if (result.statusStr.equals("SUCCESS")) {
                    updateVView(result);
                    vLoadingView.onLoadSuccess();
                } else {
                    vCurPage--;
                    LogUtils.logNetError("获取会员日商家失败---"+result.statusStr);
                    ViewUtils.showToast(mActivity, R.string.network_error);
                    vLoadingView.onLoadFailed();
                }
            }

            @Override
            public void onFailure(int resultCode) {
                vCurPage--;
                LogUtils.logNetError("获取会员日商家失败---"+resultCode);
                ViewUtils.showToast(mActivity, R.string.network_error);
                vLoadingView.onLoadFailed();
            }

        });

        NetClient.httpPost(req);
    }

    /**
     * 更新会员日商家UI
     * 
     * @param result
     */
    private void updateVView(GetDayMerListResponse result) {
        vCounts = Integer.valueOf(result.total);
        // 如果返回的商家数量为0，点击更多按钮，跳到新界面显示所有的会员日商家
        if (vCounts == 0) {
            vMoreBtn.setVisibility(View.VISIBLE);
            vMoreBtn.setText("今日无特惠商家，点击查看其它会员日");
            vMoreBtn.setOnClickListener(clickToMoreVipShops);
        }
        if (vCounts > 0) {
            int retCounts = result.dayMerList.size();
            vIndex = vIndex + retCounts;
            if (vIndex < vCounts) {
                // 服务端还有数据没有取完的时候，点击更多按钮，会继续获取下一批数据
                setForMoreBtn(vMoreBtn, true);
            } else {
                // 服务端没有数据的时候，点击更多按钮，跳到新界面显示所有的会员日商家
                vMoreBtn.setVisibility(View.VISIBLE);
                vMoreBtn.setOnClickListener(clickToMoreVipShops);
            }
            List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();
            for (int i = 0; i < retCounts; i++) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("coverUrl", result.dayMerList.get(i).midPhotoUrl);
                map.put("name", result.dayMerList.get(i).merchantName);
                map.put("disContent", result.dayMerList.get(i).preferential);
                map.put("discount",
                        getDiscountType(result.dayMerList.get(i).preferentialType));
                map.put("endTime",
                        "结束时间：" + dealEndTime(result.dayMerList.get(i).endTime));
                map.put("merchantId", result.dayMerList.get(i).merchantId);
                data.add(map);
            }
            if (vShopAdapter == null) {
                vShopAdapter = new V_ShopListAdapter(mActivity, data);
                vShopListView.setAdapter(vShopAdapter);
            } else {
                vShopAdapter.getData().addAll(data);
                vShopAdapter.notifyDataSetChanged();
            }
        }
    }

    /**
     * 根据优惠类型代号返回优惠类型描述
     * 
     * @param code
     * @return
     */
    public static String getDiscountType(String code) {
        if (code.equals("0")) {
            return "免费";
        } else if (code.equals("1")) {
            return "赠送";
        } else {
            return "打折";
        }
    }

    /**
     * 处理会员日商家的结束时间字段，返回格式为20140521XXXX。取前8位，返回年月日。
     * 
     * @param endTime
     * @return
     */
    public static String dealEndTime(String endTime) {
        int length = endTime.length();
        StringBuilder builder = new StringBuilder();
        if (length >= 4) {
            builder.append(endTime.substring(0, 4));
            builder.append("年");
        }
        if (length >= 6) {
            builder.append(endTime.substring(4, 6));
            builder.append("月");
        }
        if (length >= 8) {
            builder.append(endTime.substring(6, 8));
            builder.append("日");
        }
        return builder.toString();
    }

    /**
     * 联网获取精选商家数据
     * 
     * @param isLaunchCalled
     *            是否是在启动的时候调用该方法
     */
    private boolean isLaunchCalledSuccess = false;// 启动时调用是否成功

    private void onGetBrandList(final boolean isLaunchCalled) {
        if (fIndex != 0 && fIndex >= fCounts)
            return;
        GetBrandListRequest request = new GetBrandListRequest(DG_AREA_NUM);
        request.add(GetBrandListRequest.PAGE_NUM, (++fCurPage) + "");
        request.add(GetBrandListRequest.PAGE_SIZE, PAGE_SIZE + "");
        request.encryption();
        request.setActionListener(new ActionListener<GetBrandListResponse>() {

            @Override
            public void onSuccess(GetBrandListResponse result) {
                LogUtils.logNetReturn(Constants.getBrandList, result.responseStr);
                Log.i("test", Constants.getBrandList + "\n"
                        + result.responseStr);
                if (result.statusStr.equals("SUCCESS")) {
                    fLoadingView.onLoadSuccess();
                    // 如果第一次调用该方法成功，说明已经更新过UI了，就不要重复更新UI
                    if (isLaunchCalled && isLaunchCalledSuccess)
                        return;
                    isLaunchCalledSuccess = true;
                    updateFView(result);
                } else {
                    fCurPage--;
                    LogUtils.logNetError("获取精选商家失败---"+result.statusStr);
                    ViewUtils.showToast(mActivity, R.string.network_error);
                    fLoadingView.onLoadFailed();
                }
            }

            @Override
            public void onFailure(int resultCode) {
                fCurPage--;
                fLoadingView.onLoadFailed();
                LogUtils.logNetError("获取精选商家失败---"+resultCode);
                ViewUtils.showToast(mActivity, R.string.network_error);
            }
        });
        NetClient.httpPost(request);
    }

    /**
     * 更新精选商家UI
     * 
     * @param result
     */
    private void updateFView(GetBrandListResponse result) {
        fCounts = Integer.valueOf(result.total);
        if (fCounts > 0) {
            int retCounts = result.brandList.size();
            fIndex = fIndex + retCounts;
            if (fIndex < fCounts) {
                setForMoreBtn(fMoreBtn, true);
            } else {
                setForMoreBtn(fMoreBtn, false);
            }
            List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();
            for (int i = 0; i < retCounts; i++) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("coverUrl", result.brandList.get(i).midPhotoUrl);
                map.put("name", result.brandList.get(i).name);
                map.put("description", result.brandList.get(i).describe);
                map.put("brandId", result.brandList.get(i).brandId);
                data.add(map);
            }
            if (fShopAdapter == null) {
                fShopAdapter = new F_ShopListAdapter(mActivity, data);
                fShopListView.setAdapter(fShopAdapter);
            } else {
                fShopAdapter.getData().addAll(data);
                fShopAdapter.notifyDataSetChanged();
            }
        }
    }

    /**
     * 设置精选商家的更多按钮状态。
     * 
     * @param btn
     * @param hasMore
     */
    private void setForMoreBtn(Button btn, boolean hasMore) {
        btn.setVisibility(View.VISIBLE);
        if (hasMore) {
            btn.setClickable(true);
            btn.setText(R.string.click_for_more);
        } else {
            btn.setClickable(false);
            btn.setText(R.string.no_more);
        }
    }

    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch (checkedId) {
            case R.id.ra_btn1:
                mTabHost.setCurrentTabByTag("精选商家");
                break;

            case R.id.ra_btn2:
                mTabHost.setCurrentTabByTag("会员日商家");
                break;
        }

    }

    /**
     * 显示最新活动视图。根据接口数据决定是否要显示
     * 
     */
    public void showNewestActyView(View parentView) {
        newestActivitiesView.setVisibility(View.VISIBLE);
        newestActivities = (GridView) parentView
                .findViewById(R.id.grid_v_newest_activities);
        newestActivities.setAdapter(new NewActysAdapter(mActivity, StaticData
                .getNewestActivity(), R.layout.view_activities_grid_v_item,
                new String[] { "imageUrl" },
                new int[] { R.id.image_v_activities_item }));
        newestActivities.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                // *******点击活动的事件添加**********//
                Intent intent = new Intent(mActivity,
                        ActivityDetailActivity.class);
                if (position == 0) {
                    intent.putExtra("imageUrl", R.drawable.pic_activity1_detail);
                } else if (position == 1) {
                    intent.putExtra("imageUrl", R.drawable.pic_activity2_detail);
                }
                startActivity(intent);

            }
        });

    }

}
